﻿using Microsoft.AspNetCore.Mvc;
using MVC_System.DTO.WXT;
using MVC_System.DTO.WXTCraft;
using Newtonsoft.Json;
using WMS_MAV;

namespace MVC_System.Controllers
{
    public class CraftController : Controller
    {
        private readonly IConfiguration _configuration;

        public CraftController(IConfiguration configuration)
        {
            _configuration = configuration;
        }

        /// <summary>
        /// 工艺显示
        /// </summary>
        /// <returns></returns>
        public IActionResult CraftShow()
        {
            return View();
        }
        /// <summary>
        /// 工艺管理显示
        /// </summary>
        /// <param name="craftShow"></param>
        /// <returns></returns>
        /// 
        [HttpGet]
        public async Task<ActionResult> GetCraftShow(CraftShowDTO craftShow)
        {
            HttpClientWrapper client = new HttpClientWrapper(craftShow.Token);
            string url = _configuration["Url"] + "WXT/api/Craft/CraftShow?pageIndex=" +craftShow.pageIndex+ "&pageSize="+craftShow.pageSize+ "&craftManagenumbering="+craftShow.craftManagenumbering+ "&craftManageName="+craftShow.craftManageName+ "&craftManageState="+craftShow.craftManageState;
            var response = await client.GetAsync(url);
            return Json(response);
        }
        /// <summary>
        /// 工艺添加
        /// </summary>
        /// <returns></returns>
        public IActionResult CraftAdd()
        {
            return View();
        }
        /// <summary>
        /// 添加工艺管理
        /// </summary>
        /// <param name="token"></param>
        /// <param name="field"></param>
        /// <returns></returns>
        /// 
        [HttpPost]
        public async Task<ActionResult> GetCraftAdd(string token,CraftDTO field)
        {
            HttpClientWrapper client = new HttpClientWrapper(token);
            string url = _configuration["Url"] + "WXT/api/Craft/CraftAdd";
            string list = JsonConvert.SerializeObject(field);
            var response = await client.PostAsync(url,list);
            return Json(response);
        }
        /// <summary>
        /// 工艺删除
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        /// 
        [HttpPost]
        public async Task<ActionResult> GetDeleteCraft(CraftDeleteDTO dto)
        {
            HttpClientWrapper client = new HttpClientWrapper(dto.Token);
            string url = _configuration["Url"] + "WXT/api/Craft/CraftDeletees";
            var list = "{\"craftManageId\":" + dto.Data + "}";
            var response = await client.PostAsync(url, list);
            return Json(response);
        }
        /// <summary>
        /// 工艺批量删除
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        /// 
        [HttpPost]
        public async Task<ActionResult> GetDeleteesCraft(CraftDeleteDTO dto)
        {
            HttpClientWrapper client = new HttpClientWrapper(dto.Token);
            string url = _configuration["Url"] + "WXT/api/Craft/CraftDeletees";
            var list = "{\"craftManageId\":" + dto.Data + "}";
            var response = await client.PostAsync(url, list);
            return Json(response);
        }
        /// <summary>
        /// 工艺修改
        /// </summary>
        /// <returns></returns>
        public IActionResult CraftUpdate()
        {
            return View();
        }
        /// <summary>
        /// 工艺反填
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        public async Task<ActionResult> GetCraftBackFill(CraftBackFillDTO dto)
        {
            HttpClientWrapper client = new HttpClientWrapper (dto.Token);
            string url = _configuration["Url"] + "WXT/api/Craft/CraftBackfill?craftManageId=" + dto.craftManageId;
            var response = await client.GetAsync(url);
            return Json(response);
        }
        /// <summary>
        /// 修改入库管理
        /// </summary>
        /// <param name="token"></param>
        /// <param name="dto"></param>
        /// <returns></returns>
        /// 
        [HttpPost]
        public async Task<ActionResult> GetCraftUpdate(string token,CraftUpdateDTO dto)
        {
            HttpClientWrapper client = new HttpClientWrapper(token);
            string url = _configuration["Url"] + "WXT/api/Craft/CraftUpdate";
            string list = JsonConvert.SerializeObject(dto);
            var response = await client.PostAsync(url, list);
            return Json(response);
        }
        /// <summary>
        /// 工序查询
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        /// 
        [HttpGet]
        public async Task<ActionResult> ProcessShow(ProcessShowDTO dto)
        {
            HttpClientWrapper client = new HttpClientWrapper(dto.Token);
            string url = _configuration["Url"] + "RawApi/api/Process/ProcessShow?PageIndex=" + dto.PageIndex + "&PageSize=" + dto.PageSize + "&ProcessNumebring=" + dto.ProcessNumebring + "&ProcessName=" + dto.ProcessName + "&ProcessStatus=" + dto.ProcessStatus;
            var respomse = await client.GetAsync(url);
            return Json(respomse);
        }
        /// <summary>
        /// 工序反填
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        /// 
        [HttpGet]
        public async Task<ActionResult> ProcessModel(ProcessBackFillDTO dto)
        {
            HttpClientWrapper client = new HttpClientWrapper(dto.Token);
            string url = _configuration["Url"] + "RawApi/api/Process/ProcessMondel?id=" + dto.id;
            var respomse = await client.GetAsync(url);
            return Json(respomse);
        }
    }
}
